import request from '@/utils/request';
import URLS from './APIUrlDefine';
import { CURRENT_TOKEN } from '@/components/Authorized/renderAuthorize';

export async function GetResultList(data: any): Promise<any> {
    return request(`${URLS.GET_EXAM_RESULT_LIST}/${data.current}/${data.pageSize}`, {
        method: 'GET',
        headers: {
            Authorization: `Bearer ${CURRENT_TOKEN}`,
            'content-type': 'application/json',
        },
        params: data
    }).then((response) => {
        const data = response.data;
        const result = {
            data: data.records,
            total: data.total,
            success: true,
            pageSize: data.size,
            current: parseInt(`${data.current}`, 10) || 1,
        };
        return Promise.resolve(result);
    });
}


//获取考试结果详情
export async function GetExamResult(data: any): Promise<any> {
    return request(`${URLS.GET_EXAM_RESULT}`, {
        method: 'GET',
        headers: {
            Authorization: `Bearer ${CURRENT_TOKEN}`,
            'content-type': 'application/json',
        },
        params: data
    }).then((response) => {
        const data = response.data;
        const result = {
            data: data.records,
            total: data.total,
            success: true,
            pageSize: data.size,
            current: parseInt(`${data.current}`, 10) || 1,
        };
        return Promise.resolve(data[0]);
    });
}

export async function GetExamPaper(data: any): Promise<any> {
    return request(`${URLS.GET_EXAM_PAPER}`, {
        method: 'GET',
        headers: {
            Authorization: `Bearer ${CURRENT_TOKEN}`,
            'content-type': 'application/json',
        },
        params: data
    }).then((response) => {
        const data = response.data;
        return Promise.resolve(data);
    });
}